package com.imut.oa.controller.admin;

import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.PageResult;
import com.imut.oa.common.ResultUtils;
import com.imut.oa.pojo.dto.EmployeeIdDTO;
import com.imut.oa.pojo.dto.EmployeePageQueryDTO;
import com.imut.oa.pojo.dto.UpdateEmoployeeDTO;
import com.imut.oa.pojo.entity.User;
import com.imut.oa.service.EmployeeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/employee")
@Slf4j
@Tag(name = "员工管理")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    /**
     * 员工分页查询
     * @param employeePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @Operation(summary = "员工分页查询")
    public BaseResponse<PageResult> page (EmployeePageQueryDTO employeePageQueryDTO){
        log.info("员工分页查询：{}",employeePageQueryDTO);
        PageResult pageResult = employeeService.getEmployeePage(employeePageQueryDTO);
        return ResultUtils.success(pageResult);
    }

    /**
     * 员工禁用
     * @param id
     * @return
     */
    @PostMapping("/disableEnabling")
    public BaseResponse<List<User>> disableEnabling(@RequestBody EmployeeIdDTO dto ) {
        Long id = dto.getId();
        log.info("禁用员工：{}", id);
        employeeService.disableEnablingEmployee(id);
        return ResultUtils.success();
    }
    @PutMapping
    public BaseResponse update(@RequestBody UpdateEmoployeeDTO dto ) {
        log.info("修改员工：{}", dto);
        employeeService.updateEmoployee(dto);
        return ResultUtils.success();
    }
    @GetMapping("/allEmployee")
    public BaseResponse allEmployeeName(){
        return ResultUtils.success(employeeService.getAllEmployee());
    }
}
